package com.ideaction.service;

import com.ideaction.entity.func.FuncControll;
import com.ideaction.globalconst.ParamKey;
import com.ideaction.req.PlayerCommonReqBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class FuncontrolService {
    
    @Autowired
    private MongoTemplate funcMongoTemplate;
    
    public List<FuncControll> getFuncList(PlayerCommonReqBody playerCommonReqBody) {
        
        String channel = playerCommonReqBody.getParam(ParamKey.CHANNEL);
        String version = playerCommonReqBody.getParam(ParamKey.VERSION);
        List<FuncControll> funcList = funcMongoTemplate.findAll(FuncControll.class);
        if (funcList == null) {
            return Collections.emptyList();
        }
        return funcList.stream().filter(e -> e.hit(channel, version)).collect(Collectors.toList());
        
    }
}
